package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.BaseResult
import com.amir.common.beans.PickingWarehouseEntity
import com.amir.common.mvp.model.Model
import com.amir.common.mvp.presenter.BasePresenter
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.google.gson.JsonElement
import com.help10000.rms.mvp.view.PickingView

class PickingPresenter(view: PickingView) : BasePresenter<PickingView>(view) {
    /**
     * 获取邻料列表
     */
    fun pickingListData(repairId: String) {
        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val pickingListData = Model.getServer().pickingListData(AccessToken, repairId)
        Model.getObservable(
            pickingListData,
            object : CustomObserver<PickingWarehouseEntity>(mvpView) {

                override fun success(t: PickingWarehouseEntity) {
                    mvpView?.wareHouseList(t.data)
                }
            })
    }

    /**
     * 删除物料
     */
    fun deletePicking(repairId: String, itemId: Int) {
        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val pickingListData = Model.getServer().deletePicking(AccessToken, repairId, itemId)
        Model.getObservable(pickingListData, object : CustomObserver<BaseResult>(mvpView) {

            override fun success(t: BaseResult) {
                mvpView?.deletePickingSucc()
            }
        })
    }

    /**
     * 更换仓库
     */
    fun changeWareHouse(wareId: Int, repairId: String?) {
        val AccessToken = SPUtils.getString(Constant.AccessToken)
        val wareChange = Model.getServer().changeWarehouse(AccessToken, wareId, repairId)
        Model.getObservable(wareChange, object : CustomObserver<JsonElement>(mvpView) {
            override fun success(t: JsonElement) {

            }
        })
    }

}
